package com.noble.glamour.ui.user.check;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;

import com.noble.glamour.R;
import com.noble.glamour.bean.center.user.detail.UserDetail;
import com.noble.glamour.module.logic.application.ModuleMgr;
import com.noble.glamour.module.logic.baseui.flow.TagAdapter;
import com.noble.glamour.module.logic.baseui.flow.TagFlowLayout;
import com.noble.glamour.ui.user.util.CenterConstant;
import com.noble.library.log.PToast;
import com.noble.library.view.base.BasePanel;

import java.util.ArrayList;
import java.util.List;

/**
 * 查看他人资料底部panel
 */
public class UserCheckInfoFootPanel extends BasePanel {
    private final int channel;
    private UserDetail userDetail;   // 用户资料

    private List<String> labels = new ArrayList<>(); // 标签
    private TagFlowLayout mFlowLayout;

    public UserCheckInfoFootPanel(Context context, int channel, UserDetail userProfile) {
        super(context);
        setContentView(R.layout.p1_user_checkinfo_footer);
        this.channel = channel;
        this.userDetail = userProfile;
        initView();
    }

    private void initView() {
        if (channel == CenterConstant.USER_CHECK_INFO_OWN) {
            userDetail = ModuleMgr.getCenterMgr().getMyInfo();
        }
        if (userDetail == null) {
            PToast.showShort(getContext().getString(R.string.user_other_info_req_fail));
            return;
        }
        initLabel();
        initBase();
        initContact();
    }

    private void initLabel() {
        mFlowLayout = (TagFlowLayout) findViewById(R.id.flowlayout);

        mFlowLayout.removeAllViews();
        if (labels != null) labels.clear();

        labels.add("音乐");
        labels.add("电影");
        labels.add("交友");
        labels.add("户外");
        labels.add("旅游");

        mFlowLayout.setAdapter(new TagAdapter<String>(labels) {
            @Override
            public View getView(com.noble.glamour.module.logic.baseui.flow.FlowLayout parent, int position, String s) {
                TextView tv = (TextView) LayoutInflater.from(getContext()).inflate(R.layout.p1_flow_tv,
                        mFlowLayout, false);
                tv.setText(s);
                return tv;
            }
        });
    }

    private void initBase() {
        TextView gender = (TextView) findViewById(R.id.check_gender);
        TextView age = (TextView) findViewById(R.id.check_age);
        TextView edu = (TextView) findViewById(R.id.check_edu);
        TextView address = (TextView) findViewById(R.id.check_address);
        TextView place = (TextView) findViewById(R.id.check_native);
        TextView income = (TextView) findViewById(R.id.check_income);
        TextView school = (TextView) findViewById(R.id.check_school);
        TextView star = (TextView) findViewById(R.id.check_star);
        TextView sign = (TextView) findViewById(R.id.check_sign);

        gender.setText(getContext().getString(R.string.user_base_gender, userDetail.isMan() ? "男" : "女"));
        age.setText(getContext().getString(R.string.user_base_age, userDetail.getAge()));
        edu.setText(getContext().getString(R.string.user_base_edu, userDetail.getEdu()));
        address.setText(getContext().getString(R.string.user_base_address, userDetail.getAddressShow()));
        place.setText(getContext().getString(R.string.user_base_place, userDetail.getAddress()));
        income.setText(getContext().getString(R.string.user_base_income, userDetail.getIncome()));
        school.setText(getContext().getString(R.string.user_base_school, userDetail.getEdu()));
        star.setText(getContext().getString(R.string.user_base_star, userDetail.getStar()));
        sign.setText(getContext().getString(R.string.user_base_sign, userDetail.getAboutme()));
    }

    private void initContact() {
        TextView weChat = (TextView) findViewById(R.id.check_wx);
        TextView qq = (TextView) findViewById(R.id.check_qq);
        TextView mobile = (TextView) findViewById(R.id.check_mobile);

        weChat.setText(getContext().getString(R.string.user_contact_wx, "保密"));
        qq.setText(getContext().getString(R.string.user_contact_qq, "送礼可查"));
        mobile.setText(getContext().getString(R.string.user_contact_mobile, userDetail.getMobile()));
    }
}
